package com.puman.beautyfarmcounselor.ui.setting.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.puman.beautyfarmcounselor.MainActivity;
import com.puman.beautyfarmcounselor.R;
import com.puman.beautyfarmcounselor.ui.home.WebFragment;
import com.puman.beautyfarmcounselor.ui.setting.model.Msg;
import com.puman.beautyfarmcounselor.ui.setting.model.MsgData;
import com.puman.beautyfarmcounselor.util.univasalImage.UniversalImageLoadTool;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Curry on 2015/6/12.
 */
public class MsgListAdapter extends RecyclerView.Adapter<MsgListAdapter.ViewHolder> {

    static Context context;
    private List<MsgData> messageInfos;

    public MsgListAdapter(Context context, List<MsgData> messageInfos) {
        super();
        this.context = context;
        this.messageInfos = messageInfos;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView msg_img;
        TextView msg_content;
        TextView msg_title;
        RelativeLayout itemLayout;

        public ViewHolder(View v) {
            super(v);
            this.msg_img = (ImageView) v.findViewById(R.id.msg_img);
            this.msg_content = (TextView) v.findViewById(R.id.msg_content);
            this.msg_title = (TextView) v.findViewById(R.id.msg_title);
            this.itemLayout = (RelativeLayout) v.findViewById(R.id.item_layout);
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                        Toast.makeText(context, getPosition() + "-------", Toast.LENGTH_LONG).show();
                }
            });
        }

        public ImageView getMsg_img() {
            return this.msg_img;
        }

        public TextView getMsg_content() {
            return this.msg_content;
        }

        public TextView getMsg_title() {
            return this.msg_title;
        }

        public void setMsg_content(TextView msg_content) {
            this.msg_content = msg_content;
        }

        public void setMsg_img(ImageView msg_img) {
            this.msg_img = msg_img;
        }

        public void setMsg_title(TextView msg_title) {
            this.msg_title = msg_title;
        }


    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.msg_list_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.msg_title.setText(messageInfos.get(position).getMsg_title());
        holder.msg_content.setText(messageInfos.get(position).getMsg_introduce());
        holder.msg_img.setImageResource(R.drawable.tel);
        UniversalImageLoadTool.display(messageInfos.get(position).getMsg_icon().trim(), (ImageView) holder.msg_img,
                R.mipmap.ic_launcher);
        holder.itemLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.getInstace().getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.content_none_bottom, new WebFragment(messageInfos.get(position).getMsg_title(), messageInfos.get(position).getMsg_url())).addToBackStack(null).commit();

            }
        });

    }

    @Override
    public int getItemCount() {
        return messageInfos.size();
    }


}
